package mm.util;

import java.util.Map;
import java.util.HashMap;

public class PairSet<F, B> {

	// TODO why does TreeMap cause ClassCastException?
	private Map<F, B> fooMap=new HashMap<F, B>();
	private Map<B, F> barMap=new HashMap<B, F>();
	
	public F getFoo(B bar){
		return (F) barMap.get(bar);
	}
	
	public B getBar(F foo){
		return (B) fooMap.get(foo);
	}
	
	public void put(F foo, B bar){
		if(fooMap.containsKey(foo)){
			LOG.error("Foo "+foo+" already exists!");
		}else if(barMap.containsKey(bar)){
			LOG.error("Bar "+bar+" already exists!");
		}else{
			fooMap.put(foo, bar);
			barMap.put(bar, foo);
		}
	}
	
	public boolean containsFoo(F foo){
		return fooMap.containsKey(foo);
	}
	
	public boolean containsBar(B bar){
		return barMap.containsKey(bar);
	}

	public Map<B, F> barMap() {
		return barMap;
	}

	public Map<F, B> fooMap() {
		return fooMap;
	}

}
